package com.dai.chun.dao.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.dai.chun.dao.dao.SubsidyDao;
import com.dai.chun.dao.impl.DepartmentDaoImpl;
import com.dai.chun.dao.impl.SubsidyDaoImpl;
import com.dai.chun.dao.model.Department;
import com.dai.chun.dao.model.Subsidy;
import com.dai.chun.util.PageSplitUtil;
public class SubsidyAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private SubsidyDao subsidyDao;
	private Subsidy subsidy;
	private List<Subsidy> subsidyList;
	private PageSplitUtil psu;
	private Department department;
	private List<Department> deptList;
	
	//添加
	public String addSubsidy() throws IOException, SQLException{
		subsidyDao=new SubsidyDaoImpl();
		/*if(subsidy.getSubsidy_birth()!=null){
			subsidy.setSubsidy_birth
			(new SimpleDateFormat("yyyy-MM-dd").format(subsidy.getSubsidy_birth()));
		}*/
		subsidyDao.save(subsidy);
		return "addSubsidy";
	}
	public String showAddSubsidy(){
		DepartmentDaoImpl departmentDao=new DepartmentDaoImpl();
		setDeptList(departmentDao.listDepartment());
		return "showAddSubsidy";
	}
	
	public String listSubsidy() throws IOException, SQLException{
		subsidyDao=new SubsidyDaoImpl();
		if(psu==null){
			psu=new PageSplitUtil(1);
		}
		psu.comput();
		psu.computPageCount(subsidyDao.findAllCount());
		subsidyList=subsidyDao.listSubsidy(psu);
		return "listSubsidy";
	}
	public String listSubsidyByDeptId() throws IOException, SQLException{
		subsidyDao=new SubsidyDaoImpl();
		if(psu==null){
			psu=new PageSplitUtil(1);
		}
		psu.comput();
		psu.computPageCount(subsidyDao.findAllCount());
		subsidyList=subsidyDao.listSubsidyByDeptId(psu,department.getDept_id());
		return "listByDeptIdSubsidy";
	}
	
	//删除
	public String delSubsidy() throws SQLException{
		subsidyDao=new SubsidyDaoImpl();
		subsidyDao.delSubsidy(subsidy.getSubsidy_id());
		return "delSubsidy";
	}
	
	//修改
	public String updateSubsidy() throws SQLException{
		subsidyDao=new SubsidyDaoImpl();
		subsidyDao.updateSubsidy(subsidy);
		return "updateSubsidy";
	}
	
	public String showUpdateSubsidy() throws SQLException{
		subsidyDao=new SubsidyDaoImpl();
		subsidy=subsidyDao.findSubsidyById(subsidy.getSubsidy_id());
		DepartmentDaoImpl departmentDao=new DepartmentDaoImpl();
		setDeptList(departmentDao.listDepartment());
		return "showUpdateSubsidy";
	}
	
	
	public List<Subsidy> getSubsidyList() {
		return subsidyList;
	}
	public void setSubsidyList(List<Subsidy> subsidyList) {
		this.subsidyList = subsidyList;
	}
	
	public Subsidy getSubsidy() {
		return subsidy;
	}
	public void setSubsidy(Subsidy subsidy) {
		this.subsidy = subsidy;
	}

	public PageSplitUtil getPsu() {
		return psu;
	}

	public void setPsu(PageSplitUtil psu) {
		this.psu = psu;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public List<Department> getDeptList() {
		return deptList;
	}

	public void setDeptList(List<Department> deptList) {
		this.deptList = deptList;
	}

}
